var iosCheck = function(){
    var u = navigator.userAgent, app = navigator.appVersion;
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    var moveType = true;
    if( isiOS == true ){
        moveType = true;
    }else{
        moveType = false;
    }
    return moveType;
}
$(function(){
    var follow = iosCheck() ;
    var tabsSwiper = new Swiper('.swiper-container',{
        pagination: '.swiper-pagination',
        centeredSlides : true,
        slidesPerView : 1.3,
        spaceBetween : 10,
        speed:500,
        followFinger : follow,
        onInit: function(swiper){
          // $(".swiper-slide").eq(0).find(".pro-type-accident").attr("id","pro-type-char-wyp");
          load(obj);
          $(".swiper-container").css("opacity","1");
          $(".swiper-pagination").show();
          $(".swiper-slide").removeClass("slider-bigger").addClass("slider-small");
          $(".swiper-slide").eq(0).removeClass("slider-small").addClass("slider-bigger");
        },
        onSlideChangeStart: function(){
            $(".swiper-slide").removeClass("slider-bigger").addClass("slider-small");
            $(".swiper-slide").eq(tabsSwiper.activeIndex).removeClass("slider-small").addClass("slider-bigger");
            var tab = $(".swiper-slide").eq(tabsSwiper.activeIndex).find(".pro-type-accident").attr("id");
            var bgSrc = $("#bg-hide").find("img[alt='#"+tab+"']").attr("src");
            $(".pro-list-contain").css("background-image",'url('+bgSrc+')');
            if(tabsSwiper.activeIndex == "0"){
                $(".pro-list-contain").attr("style","");
            }
        }
    });
    
});
    var imgLink = "../../image/pro/";
    var obj=
    [
             {target:'#pro-type-special-wxb',bg:[""+imgLink+"img_special_wxb.jpg",""+imgLink+"bg_special_wxb.jpg",]},
             {target:'#pro-type-char-wyp',bg:[""+imgLink+"img_char_wyp.jpg",""+imgLink+"bg_char_wyp.jpg",]},
             {target:'#pro-type-travel-hy',bg:[""+imgLink+"img_travel_hy.jpg",""+imgLink+"bg_travel_hy.jpg",]},
             {target:'#pro-type-accident-yyjt',bg:[""+imgLink+"img_accident_jt.jpg",""+imgLink+"bg_accident_jt.jpg",]},
             {target:'#pro-type-accident-hy',bg:[""+imgLink+"img_accident_hy.jpg",""+imgLink+"bg_accident_hy.jpg",]},
             {target:'#pro-type-travel-ly',bg:[""+imgLink+"img_travel_ly.jpg",""+imgLink+"bg_travel_ly.jpg",]},
             {target:'#pro-type-health-nx',bg:[""+imgLink+"img_health_nx.jpg",""+imgLink+"bg_health_nx.jpg",]},
             {target:'#pro-type-health-zy',bg:[""+imgLink+"img_health_zy.jpg",""+imgLink+"bg_health_zy.jpg",]},
             {target:'#pro-type-health-zy',bg:[""+imgLink+"img_health_zy.jpg",""+imgLink+"bg_health_zy.jpg",]},
             {target:'#pro-type-health-zy',bg:[""+imgLink+"img_health_zy.jpg",""+imgLink+"bg_health_zy.jpg",]},
             {target:'#pro-type-health-zy',bg:[""+imgLink+"img_health_zy.jpg",""+imgLink+"bg_health_zy.jpg",]},
    ];
    var load = function(obj){
        var nowLen = obj.length;
        for(var i=0;i<nowLen;i++){
            var shiftObj = obj.shift();
            var imgObj = shiftObj['bg'];
            var target = shiftObj['target'];
            //for(var z in imgObj){
                var img = new Image();
                img.alt = target;
                img.src = imgObj[0];
                img.onload = function(e){
                    // console.log(e.target.alt);
                    $(e.target.alt).find('.pro-type-img').css({'background-image':'url('+e.target.src+')'});
                    $(e.target.alt).find('.pro-type-img').removeClass('pro-animation');
                };

                var imgbg = new Image();
                imgbg.alt = target;
                imgbg.src = imgObj[1];
                imgbg.onload = function(e){
                    // console.log(e.target.alt);
                    // $('.pro-list-contain').css('background-image','url('+e.target.src+')');
                    $("#bg-hide").append(e.target);
                };
        }
    };